/**
 * URI Object 
 * @Author:liuricheng
 * @Time:2013-10-18
 *
 */
var Uri					=	new Object();

Uri.getUri = function(){
	return location.href.substring(0,(location.href.lastIndexOf("/")));
}


Uri.getBasePath = function(){
	var curWwwPath 		= 	window.document.location.href;
	var pathName 		= 	window.document.location.pathname;
	var pos 			= 	curWwwPath.indexOf(pathName);
	var localhostPath 	= 	curWwwPath.substring(0, pos);
	var projectName 	= 	pathName.substring(0, pathName.substr(1).indexOf('/') + 1);	
	if(projectName.length > 0) return (localhostPath + projectName);
	else  return localhostPath;
}

Uri.getRootPath = function(){
	var curWwwPath 		= 	window.document.location.href;
	var pathName 		= 	window.document.location.pathname;
	var pos 			= 	curWwwPath.indexOf(pathName);
	var localhostPath 	= 	curWwwPath.substring(0, pos);
	var projectName 	= 	pathName.substring(0, pathName.substr(1).indexOf('/') + 1);	
	//if(projectName.length > 0) return (localhostPath + projectName);
	return localhostPath;
}


/* $Id: listtable.js 14980 2008-10-22 05:01:19Z  Author:liuricheng  
 * Before useing,load jquery.js. 
 * 
 */
function getRootPath(){
    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath=window.document.location.href;
    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8083
    var localhostPaht=curWwwPath.substring(0,pos);
    //获取带"/"的项目名，如：/uimcardprj
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    //return(localhostPaht+projectName);
    return projectName;
}


var listTable 		= new Object;

listTable.opt = {
	dataType:'json',
	type:'post'
};

listTable.query = "query";
listTable.filter = new Object;
listTable.url = location.href.lastIndexOf("?") == -1 ? location.href.substring((location.href.lastIndexOf("/")) + 1) : location.href.substring((location.href.lastIndexOf("/")) + 1, location.href.lastIndexOf("?"));
listTable.url += "?is_ajax=1";
listTable.imgUrl = Uri.getRootPath() + '/baby/Public/image/admin';

/**
 * Initialize  
 * 
 */
listTable.init = function(ajaxUrl,imgUrl){	
	if(typeof ajaxUrl != 'undefined')	listTable.url 	= 	ajaxUrl;
	if(typeof imgUrl != 'undefined') listTable.imgUrl 	= 	imgUrl;
}

/**
 * 创建一个可编辑区
 */
listTable.edit = function(obj, field, id){
	//add code
	var tag 		= 	obj.firstChild.tagName;
	
	if (typeof(tag) != "undefined" && tag.toLowerCase() == "input"){
	    return;
	}

	/* 保存原始的内容 */
	var org 		= 	obj.innerHTML;
	var val 		= 	Browser.isIE ? obj.innerText : obj.textContent;

	  /* 创建一个输入框 */
	var txt 		= 	document.createElement("INPUT");
	txt.setAttribute('type','text');
	txt.value 		= 	(val == 'N/A') ? '' : val;
	txt.style.width = 	(obj.offsetWidth + 12) + "px" ;

	  /* 隐藏对象中的内容，并将输入框加入到对象中 */
	obj.innerHTML 	= 	"";
	obj.appendChild(txt);
	txt.focus();

	  /* 编辑区输入事件处理函数 */
	txt.onkeypress = function(e){
	    var evt 	= 	Utils.fixEvent(e);
	    var obj 	= 	Utils.srcElement(e);

	    if (evt.keyCode == 13){
			obj.blur();
			return false;
	    }

	    if (evt.keyCode == 27){
			obj.parentNode.innerHTML = org;
	    }
	}

	/* 编辑区失去焦点的处理函数 */
	txt.onblur = function(e){  
		if(Utils.trim(txt.value).length > 0){	
			$.ajax({
				url:listTable.url,
				type:'post',
				dataType:'json',
				data:{action:'edit',field:field,value:txt.value,id:id},
				beforeSend:function(){
					$('#loading').QLoading({'text':'处理中','status':'open'});
				},
				success:function(result,status){					
					if( 1 == result.data ){
						obj.innerHTML 	=  result.info;
						$('#loading').QLoading({'text':'成功','status':'close'});
					}
					else{
						obj.innerHTML 	=  org;
						$('#loading').QLoading({'text':'失败','status':'close'});
					}
				}
			});
		}
		else{	    
			obj.innerHTML = org;
		}
	}	
}

/**
 * 切换状态
 */
listTable.toggle = function(obj, field, id){				
	var val = (obj.src.match(/bg_yes.gif/i)) ? 0 : 1;
	
	$.extend(listTable.opt,{
		 url:listTable.url,
		 data:{id:id,field:field,value:val,action:'change'},
		 success:function(msg){
			 if(msg.status == 1){
				 obj.src = (msg.data > 0) ? listTable.imgUrl + '/bg_yes.gif' : listTable.imgUrl + '/bg_no.gif';
				 //art.dialog({id: 'N3690',title: false,lock:true}).content(msg.info).time(1);
			 }
			 else{
				 art.dialog({id: 'N3690',title: false,lock:true}).content(msg.info).time(1);
			 }
		 }		
	});
	$.ajax(listTable.opt);
}

/**
 * 兼容toggle方法
 *
 */
listTable.changeStatus	=	function(obj, field, id){
	var val = (obj.src.match(/bg_yes.gif/i)) ? 1 : 0;	
	$.extend(listTable.opt,{
		 url:listTable.url,
		 data:{id:id,field:field,value:val,action:'change'},
		 success:function(msg){
			 if(msg.status == 1){
				obj.src = (msg.data > 0) ? listTable.imgUrl + '/bg_yes.gif' : listTable.imgUrl + '/bg_no.gif';
			 }
			 else{
				 obj.src = (msg.data > 0) ? listTable.imgUrl + '/bg_yes.gif' : listTable.imgUrl + '/bg_no.gif';
			 }
		 }		
	});
	$.ajax(listTable.opt);	
}
	

/**
 * 切换排序方式
 */
listTable.sort = function(sort_by, sort_order)
{
   //add code 
}

/**
 * 翻页
 */
listTable.gotoPage = function(page)
{
   //add code 
}

/**
 * 载入列表
 */
listTable.loadList = function()
{
   //add code 
}

/**
 * 删除列表中的一个记录
 */

//删除数据
listTable.remove = function(id,tips,url){
	var ajaxUrl = ( typeof url != 'undefined' ) ? url : listTable.url;	
	if(confirm(tips)){
		$.extend(listTable.opt,{
			 url:ajaxUrl,
			 data:{id:id,action:'del'},
			 success:function(msg){				
				 if(msg.status == 1){					
					art.dialog({title:false, lock:true,}).content(msg.info).time(3);
					window.parent.frames['right'].location.reload();
				}
				 else{
					art.dialog({title:false, lock:true,}).content(msg.info).time(1.5);
				 }
			 }		
		});
		$.ajax(listTable.opt);		
	}	
}

//删除所有选中的
listTable.removeAll	= function(){
	
}

listTable.gotoPageFirst = function()
{
   //add code 
}

listTable.gotoPagePrev = function()
{
   //add code 
}

listTable.gotoPageNext = function()
{
   //add code 
}

listTable.gotoPageLast = function()
{
   //add code 
}

listTable.changePageSize = function(e)
{
   //add code 
}

listTable.listCallback = function(result, txt)
{
   //add code 
}

listTable.selectAll = function(obj, chk){
	//add code 
	if (chk == null){
		chk = 'checkboxes';
	}
	var elems = obj.form.getElementsByTagName("INPUT");
	for (var i=0; i < elems.length; i++){
		if (elems[i].name == chk || elems[i].name == chk + "[]"){
			elems[i].checked = obj.checked;
		}
	}
}

listTable.compileFilter = function()
{
   //add code 
}

listTable.getPageSize = function()
{
   //add code 
}

listTable.addRow = function(checkFunc)
{
   //add code 
}
